//
//  NSDictionary+NewAndDistance.m
//  JiaYuan
//
//  Created by Sang HsiuJane on 8/22/11.
//  Copyright 2011 JiaYuan. All rights reserved.
//

#import "NSDictionary+NewAndDistance.h"


@implementation NSDictionary(dicCompareByNewAndDistance) 

-(NSComparisonResult)dicCompareByNewAndDistance:(NSDictionary*)other
{
    //service
    int myservice =0;
    //   int otherservice=0;
    NSArray* servicesArray = ((NSArray *)[self objectForKey:@"service"]);
    if ([servicesArray count]) {
        NSString *servicesStr= [servicesArray objectAtIndex:0];
        if ([servicesStr respondsToSelector:@selector(intValue)]) {
            myservice = [servicesStr intValue];
        }
    }
    //    servicesArray = ((NSArray *)[other objectForKey:@"service"]);
    //    if ([servicesArray count]) {
    //        NSString *servicesStr= [servicesArray objectAtIndex:0];
    //        if ([servicesStr respondsToSelector:@selector(intValue)]) {
    //            otherservice = [servicesStr intValue];
    //        }
    //    }
    if (myservice == 999) {
        return NSOrderedAscending;
    }

    //if (myservice ==otherservice ) {
    float myValue = [[self objectForKey:@"dis"] floatValue];
    float otherValue= [[other objectForKey:@"dis"] floatValue];
    
    if(myValue == otherValue) return NSOrderedSame;
    return (myValue < otherValue ? NSOrderedAscending : NSOrderedDescending);
    //}
    //return (myservice > otherservice ? NSOrderedAscending : NSOrderedDescending);
    
    
    //    
    //	float myValue = [[self objectForKey:@"dis"] floatValue];
    //	float otherValue= [[other objectForKey:@"dis"] floatValue];
    //	
    //	if(myValue == otherValue) return NSOrderedSame;
    //	return (myValue < otherValue ? NSOrderedAscending : NSOrderedDescending);
}

@end
